package com.fqgj.xjd.user.dao.impl;

import com.fqgj.common.api.Page;
import com.fqgj.common.base.AbstractBaseMapper;
import com.fqgj.xjd.user.dao.UserContactAddressBookDao;
import com.fqgj.xjd.user.entity.UserContactAddressBookEntity;
import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * User: zhangxingyun
 * Date: 2017-07-20
 * Time: 18:38:53.072
 */

@Repository
public class UserContactAddressBookDaoImpl extends AbstractBaseMapper<UserContactAddressBookEntity> implements UserContactAddressBookDao {

    @Override
    public UserContactAddressBookEntity selectByUserCode(String userCode) {
        return getSqlSession().selectOne(getStatement("selectByUserCode"), userCode);
    }

    @Override
    public List<UserContactAddressBookEntity> selectFirstAndLastByUserCode(String userCode) {
        Map<String, Object> param = new HashMap<>();
        param.put("userCode", userCode);
        return getSqlSession().selectList(getStatement("selectFirstAndLastByUserCode"), param);
    }

    @Override
    public UserContactAddressBookEntity selectByUserCodeAndAppCode(String userCode, String appCode) {
        Map<String, Object> param = new HashMap<>();
        param.put("userCode", userCode);
        param.put("appCode", appCode);
        return getSqlSession().selectOne(getStatement("selectByUserCodeAndAppCode"), param);
    }

    @Override
    public List<UserContactAddressBookEntity> selectListByPage(Page page, Date endDate) {
        Map<String, Object> param = new HashMap<>();
        param.put("endDate", endDate);
        param.put("page", page);
        return getSqlSession().selectList(getStatement("selectListByPage"), param);
    }

    @Override
    public int deleteByUserCode(String userCode) {
        return getSqlSession().update(getStatement("deleteByUserCode"), userCode);
    }

    @Override
    public int updateByUserCode(String userCode, String deviceContactUrl, String smsUrl, Long id) {
        Map<String, Object> param = new HashMap<>();
        param.put("userCode", userCode);
        param.put("contactUrl", deviceContactUrl);
        param.put("smsUrl", smsUrl);
        param.put("id", id);
        return getSqlSession().update(getStatement("updateByUserCode"), param);
    }
}